import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class MyConditionAwaitRunnableTask implements Runnable {

    private ReentrantLock reentrantLock;

    private Condition condition;

    public MyConditionAwaitRunnableTask(ReentrantLock reentrantLock, Condition condition) {

        this.reentrantLock = reentrantLock;

        this.condition = condition;

    }

    @Override

    public void run() {

        try {

            reentrantLock.lock(); // 当前t2节点加到同步队列

            System.out.println(Thread.currentThread().getName() + "lock,拿到锁了");

            System.out.println(Thread.currentThread().getName() + "等待信号");

            try {

                condition.await();

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

            System.out.println(Thread.currentThread().getName() + "拿到信号");

        } finally {

            reentrantLock.unlock();

            System.out.println(Thread.currentThread().getName() + "unlock结束");

        }

    }

}
